<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8"/>
    <title>回调页面</title>
    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<script>
    window.onload = function () {
        //获取url参数
        function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] === variable) {
                    return pair[1];
                }
            }
            return '';
        }

        //url获取code
        let code = getQueryVariable('code');
        //获取token和用户信息
        $.ajax({
            url: 'http://127.0.0.1:8080/token/' + code, success: function (result) {
                localStorage.setItem('access_token', result.tokenInfo.access_token);
                localStorage.setItem('username', result.userInfo.username);
                window.location = localStorage.getItem('visitUri');
            }
        });
    };
</script>
</body>
</html>
